package com.ctrip.corp.obt.shard.infrastructure.mapper;

import com.ctrip.corp.obt.shard.annotation.InnerPluginIgnore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
@Mapper
public interface DataShardSourceMapper {

    @InnerPluginIgnore(ignoreAll = true)
    @Select({"${tableExistSql}"})
    String tableExist(String tableExistSql);

    @InnerPluginIgnore(ignoreAll = true)
    @Select({"${tableCreateSql}"})
    void tableCreate(String tableCreateSql);

    @InnerPluginIgnore(ignoreAll = true)
    @Select({"select id, tenant_id as tenantId, url, status, user_name as userName,password as password,driver_class as driverClass ,create_time as createTime from sharding_data_source where is_deleted = 0 and status in (1,2) and status=1  limit 1000"})
    Set<DataShardSourceDO> selectAllSource();


    @InnerPluginIgnore(ignoreAll = true)
    @Select({"<script> " +
            "select id, tenant_id as tenantId, url, status, user_name as userName,password as password,driver_class as driverClass ,create_time as createTime " +
            "from sharding_data_source where is_deleted = 0 and status in (1,2) and status=1 " +
            "and tenant_id in <foreach item='item' index='index' collection='tenantIds' open='(' separator=',' close=')'> #{item} </foreach> limit 1000" +
            "</script>"})
    Set<DataShardSourceDO> selectSourceByTenantIdList(@Param("tenantIds") Set<String> tenantIds);

}
